// pages/movies/movies.js
const {movie,movieSearch} = require("../../models/movie")
const {titles} = require("../../static/index")
const {transformStar} = require("../../utils/index")
Page({
  data: {
    list:{}
  },
  onLoad:async function (options){
    var tables=['comingSoon','inTheaters','top250']
    var list={}
    for(let item of tables){
      var res = await movie(item)
      res.data.result.forEach(item=>{
        if(item.title.length>6){
          item.title = item.title.slice(0,6)+'...'
        } 
        item.star = transformStar(item.rating)
      })
      list[item]={
        title:titles[item],
        result:res.data.result.slice(0,3)
      }
      this.setData({
        list
      })
    }
  },
  
  onFocus(){
    wx.navigateTo({
      url: '/pages/search/search'
    });
  }
})